#include <list>
#include <map>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;
//数据存取
// _Pred
// a binary predicate implemented as a function:
bool same_integral_part(double first, double second)
{
    return (int(first) == int(second));
}

// a binary predicate implemented as a class:
class is_near
{
public:
    bool operator()(double first, double second)
    {
        return (fabs(first - second) <= 5.0);
        // return (first == second);
    }
};

void printList(const list<double> &L)
{

    for (auto it = L.begin(); it != L.end(); it++)
    {

        cout << *it << " ";
    }

    cout << endl;
}

class MyPrint
{
public:
    void operator()(double val)
    {
        cout << val << " ";
    }
};

void test01()
{
    list<double> L1;
    L1.push_back(10);
    L1.push_back(20);
    L1.push_back(30);
    L1.push_back(40);
    L1.push_back(20);
    L1.push_back(30);
    L1.push_back(40);

    L1.push_front(45);
    // L1.pop_back();

    //cout << L1.at(0) << endl;//错误 不支持at访问数据
    //cout << L1[0] << endl; //错误  不支持[]方式访问数据
    cout << "1:" << L1.front() << endl;
    cout << "2:" << L1.back() << endl;

    //list容器的迭代器是双向迭代器，不支持随机访问
    list<double>::iterator it1 = L1.begin();
    list<double>::iterator it2 = L1.end();

    // printList(L1);
    for_each(it1, it2, MyPrint());
    cout << endl;
    L1.sort();
    L1.unique(is_near());
    // it = it + 1;//错误，不可以跳跃访问，即使是+1, 但是++it或者it++是可以的
    printList(L1);
}

void test02()
{
    typedef unsigned char BYTE;
    list<BYTE> lb;

    // lb.push_back('w');
    lb.resize(10);
    lb.push_back(25);

    for (auto it = lb.begin(); it != lb.end(); it++)
    {
        cout << *it + 1 << " " << endl;
    }
    cout << endl;
}

int main()
{

    test01();
    return 0;
}
